package com.xizi.秋招笔试;

import java.util.LinkedList;
import java.util.Scanner;

public class Main {
    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    static LinkedList<Integer> res = new LinkedList<>();

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(), m = scanner.nextInt(),
                k = scanner.nextInt();
        TreeNode[] nodes = new TreeNode[n + 1];
        for (int i = 1; i <= n; i++) nodes[i] = new TreeNode(i);
        for (int i = 1; i <= n; i++) {
            int a = scanner.nextInt(), b = scanner.nextInt();
            TreeNode node = nodes[a];
            if (a != 0) nodes[i].left = nodes[a];
            if (b != 0) nodes[i].right = nodes[b];
        }

        for (int i = 0; i < m; i++) {
            int p = scanner.nextInt();
            TreeNode t = nodes[p].left;
            nodes[p].left = nodes[p].right;
            nodes[p].right = t;
        }
        dsf(nodes[k]);

        for (int i = 0; i < res.size(); i++) {
            System.out.print(res.get(i));
            if (i != res.size() - 1) System.out.print(" ");
        }
    }

    private static void dsf(TreeNode root) {
        if (root == null) return;
        dsf(root.left);
        res.add(root.val);
        dsf(root.right);
    }
}